package com.smh.a12Test6;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class Server {
    public static void main(String[] args) throws IOException {

        ServerSocket ss = new ServerSocket(10001);

        //线程池
        ThreadPoolExecutor tpe = new ThreadPoolExecutor(
                3,//核心线程数量
                6,//线程池大小
                60,//空闲时间
                TimeUnit.SECONDS,//单位
                new ArrayBlockingQueue<>(2),//队列
                Executors.defaultThreadFactory(),//线程工厂,让线程池如何创建线程对象
                new ThreadPoolExecutor.AbortPolicy()//阻塞队列
        );

        while (true) {
            Socket accept = ss.accept();
            if (accept != null) {
                MyThread myThread = new MyThread(accept);
                tpe.submit(myThread);//加入线程池
            }
        }

//        ss.close();


    }
}
